package ViewOption;

import Pojo.Site;
import Service.SiteService;
import Utils.BaseMessage;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

public class siteVo {
    private final SiteService siteService = new SiteService();
    private final Logger logger = Logger.getLogger(siteVo.class);

    public Object getSiteAll() {
        try {
            return siteService.getSiteAll();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            logger.error(throwables.getMessage());
            return null;
        }
    }

    public Object updateSiteIsAdmin(HttpServletRequest request) {
        Site site = new Site();
        site.setSiteTitle(request.getParameter("title"));
        site.setSiteSubTitle(request.getParameter("subTitle"));
        site.setSiteContent(request.getParameter("content"));
        site.setSiteKeyword(request.getParameter("keyword"));
        try {
            if (siteService.updateSiteIsAdmin(site) < 1) {
                return new BaseMessage(2, "修改失败,请查看日志", null);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            logger.error(throwables.getMessage());
            return new BaseMessage(3, "出现异常", null);
        }
        return new BaseMessage(0, null, "修改成功");
    }
}
